﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ApiGateWay
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.Title = "API网关服务";
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args)
        {
            IWebHostBuilder builder = new WebHostBuilder();
            //注入WebHostBuilder
            return builder.ConfigureServices(service =>
            {
                service.AddSingleton(builder);
            })          
                .ConfigureAppConfiguration(conbuilder =>
                {
                    conbuilder.AddJsonFile("appsettings.json");
                    conbuilder.AddJsonFile("configuration.json");
                })
                .UseKestrel()
                .UseUrls("http://*:8000")
                .UseStartup<Startup>()//Startup.cs这个类主要做两件事情的配置Service DI和http管道，这些都是在WebHost启动之前就需要确定下来的。而UseStartup就是将我们定义的Startup.cs和 IStartup绑定起来，让WebHost可以找得到。 怎么绑定呢？ 当然还是依赖注入
                .Build();
        }
    }
}
